package com.example.springboot.ytest.ytest;

public class SystemTest {
    
    /**
     * 看哪个耗时更多
     * 
     * @author: yeyi
     * @date: 2018年6月17日
     */
    static void t_spendTime() {
        final long count = 10000;
        long startTime = System.nanoTime();
        long a = 0;
        for(int i=0; i<count; i++) {
            a = System.currentTimeMillis(); 
        }
        long end1 = System.nanoTime();
        for(int i=0; i<count; i++) {
            a = System.nanoTime(); 
        }
        long end2 = System.nanoTime();
        System.out.println("currentTimeMillis: "+(end1-startTime));
        System.out.println("nanoTime: "+(end2-end1));
    }
    
    
    /**
     * 看哪个精确度高
     * 
     * @author: yeyi
     * @date: 2018年6月17日
     */
    static void t_accuracy() {
        final int count = 500;
        long[] aCurrentTime = new long[count];
        long[] aNanoTime = new long[count];
        long startTime = System.nanoTime();
        long a = 0;
        for(int i=0; i<count; i++) {
            aCurrentTime[i] = System.currentTimeMillis(); 
        }
        long end1 = System.nanoTime();
        for(int i=0; i<count; i++) {
            aNanoTime[i] = System.nanoTime(); 
        }
        long end2 = System.nanoTime();
        StringBuilder sb = new StringBuilder();
        for(long i: aCurrentTime) {
            sb.append(i);
            sb.append(", ");
        }
        System.out.println("currentTimeMillis: "+sb.toString());
        sb = new StringBuilder();
        for(long i: aNanoTime) {
            sb.append(i);
            sb.append(", ");
        }
        System.out.println("nanoTime: "+sb.toString());
    }
    public static void main(String[] args) {
//        t_spendTime();
        t_accuracy();
    }
}
